class wxtool {
	public constructor() {
	}
	private static instance: wxtool;//单例模式
	public static get Instance(): wxtool {
		if (wxtool.instance == null) {
			wxtool.instance = new wxtool();
		}
		return wxtool.instance;
	}
	/**商品管理类 */
	private m_gameShopMgr: gameShopView = new gameShopView(this);

	/**控制看广告 */
	public add: boolean = false;
	/**商品Id */
	public shopnum: number;
	/**控制试戴 */
	public test: boolean = false;
	public openTrying: boolean = false;
	public hideTrying: boolean = false;
	public num: number;
	//打开banner广告
	public OpenBanner(id) {
		//创建banner广告
		const bannerAd = wx.createBannerAd({
			adUnitId: id,//banner id
			style: {
				left: 10,
				top: 76,
				width: 320
			}
		});
		//加载banner
		bannerAd.onLoad(() => {
			console.log('banner 广告加载成功')
			bannerAd.style.width = 400;//随时设置banner宽
			bannerAd.show();//调用打开banner
		})
		bannerAd.onError(err => {
			console.log('banner 广告加载失败' + err)
		});
		let systemData;
		wx.getSystemInfo({
			success: (res) => {
				systemData = res;
			}
		});
	}
	/**发放奖励 */
	public reward(isEnded) {
		if (isEnded) {
			// 正常播放结束，可以下发游戏奖励
			console.error("正常关闭广告了");
			/**看广告金币增加 */
			if (this.add == true) {
				if (this.num == 1) {
					GameOver.getInstance().addmoney(20);
				}
				if (this.num == 2) {
					GameOver.getInstance().addmoney(10);
				}
				if (this.num == 3) {
					GameOver.getInstance().addmoney(6);
				}
				else if (this.num > 3) {
					GameOver.getInstance().addmoney(4);
				}
				GameOver.getInstance().backToHall();
				this.add = false;
			}
			else {
				/**控制试用 */
				DataProl.userCurrentDressUp.decorateId = this.shopnum;
				this.openTrying = true;
				/**打开试用中 */
				gameShopData.getInstance().m_gameShopMgr.openTrying();

			}
		} else {
			// 播放中途退出，不下发游戏奖励
			console.error("播放中途关闭广告了");
		}
	}
	// /**本地服务器加钱 */
	// public addmoney(ss: number) {
	// 	if (DataProl.isVisitor == false) {
	// 		let value = 'accountId=' + DataProl.account + '&addMoney=' + ss;
	// 		MiniNet.post(DataProl.shopaddr, '/shop_share', value, this, this.addMoneyCallback);
	// 		console.log(12345);
	// 	}
	// }
	// public addMoneyCallback(userMoneyData) {
	// 	var userMoney = JSON.parse(userMoneyData.target.response);
	// 	DataProl.userCurrentDressUp.userMoney = userMoney;
	// };
}